package com.sly.demo.mapstruct.model.converter;

import com.sly.demo.mapstruct.model.dto.OrderDto;
import com.sly.demo.mapstruct.model.po.Order;
import com.sly.demo.mapstruct.model.vo.OrderVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 订单转换器
 *
 * @author SLY
 * @date 2022/8/7
 */
@Mapper(unmappedSourcePolicy = ReportingPolicy.WARN, unmappedTargetPolicy = ReportingPolicy.WARN)
public interface OrderConverter {

    OrderConverter INSTANCE = Mappers.getMapper(OrderConverter.class);

    /**
     * 订单实体转订单Dto
     *
     * @param order 订单实体
     * @return {@link OrderDto}
     */
    @Mappings({
            @Mapping(target = "goodsList", ignore = true),
    })
    OrderDto orderToOrderDto(Order order);

    /**
     * 订单实体List转订单DTO List
     *
     * @param orderList 订单实体List
     * @return {@link List}<{@link OrderDto}>
     */
    List<OrderDto> orderToOrderDtoList(List<Order> orderList);

    @Mappings({
            @Mapping(expression = "java(CommonExpression.parseDateToDateTimeStr(order.getCreateTime()))", target = "createTime"),
            @Mapping(expression = "java(GoodsConverter.INSTANCE.goodsDtoToGoodsVoList(order.getGoodsList()))", target = "goodsList"),
    })
    OrderVo orderDtoToOrderVo(OrderDto order);

    /**
     * 订单DtoList转订单VoList
     *
     * @param orderList 订单DtoList
     * @return {@link List}<{@link OrderVo}>
     */
    List<OrderVo> orderDtoToOrderVoList(List<OrderDto> orderList);
}
